package com.xbh.common.model;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by Doaim on 2017/4/20.
 * Model 元数据
 */
public class ModelMetaData {
    private String tableName;
    //ID
    private ArrayList<String> ids;
    private String id;
    //属性与数据库字段映射
    private Map<Field,String> fieldColumnMapping = new ConcurrentHashMap<>();
    private Map<Field,String> idFieldColumnMapping = new ConcurrentHashMap<>();
    private boolean isCompoundId = false;
    public ArrayList<String> getIds() {
        return ids;
    }

    public void setIds(ArrayList<String> ids) {
        this.ids = ids;
        this.isCompoundId = ids.size() > 1;
    }

    public void setColumnMapping(Field field,String columnName){
        fieldColumnMapping.put(field,columnName);
    }
    public void setIdColumnMapping(Field field,String columnName){
        idFieldColumnMapping.put(field,columnName);
    }
    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public boolean isCompoundId() {
        return isCompoundId;
    }

    public Map<Field, String> getFieldColumnMapping() {
        return fieldColumnMapping;
    }
    public Map<Field,String> getIdFieldColumnMapping(){
        return idFieldColumnMapping;
    }
}
